package com.monitor.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.monitor.entity.ErpServiceWeb;
import com.monitor.service.ErpServiceWebService;
import com.monitor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 服务网络表 前端控制器
 * </p>
 *
 * @author LX
 * @since 2018-09-13
 */
@RestController
@RequestMapping("/erpServiceWeb")
@Api(description="服务网络")
public class ErpServiceWebController {

    @Resource
    private ErpServiceWebService serviceWebService;


    @RequestMapping("/inertOrUpdateServiceWeb")
    @ApiOperation("添加Or修服务网络表")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Integer> inertOrUpdateInsurance(ErpServiceWeb insurance) {
        Result<Integer> result=new Result<Integer>();
        try{
            result.setCount(1);
            result.setData(serviceWebService.insertOrUpdate(insurance)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getServiceWebById")
    @ApiOperation("根据id查看服务网络信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "webId", value = "服务网络ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<ErpServiceWeb> getInsuranceById(Integer webId) {
        Result<ErpServiceWeb> result=new Result<ErpServiceWeb>();
        try{
            result.setCount(1);
            result.setData(serviceWebService.selectById(webId));
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getServiceWebPage")
    @ApiOperation("根据客户ID查询服务网络分页")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Page<ErpServiceWeb>> getUserBycustIdPage(@RequestParam(value = "page", defaultValue = "1") int page,
                                                   @RequestParam(value="limit",defaultValue="1000") int limit,String keyWord) {
        Result<Page<ErpServiceWeb>> result=new Result<Page<ErpServiceWeb>>();
        try{
            Page<ErpServiceWeb> page1=new Page<ErpServiceWeb>(page,limit);
            Page<ErpServiceWeb> carPage=serviceWebService.selectPage(page1,new EntityWrapper<ErpServiceWeb>().like("company_name", keyWord).or().like("company_address", keyWord));
            //Page<ErpCustomerCar> page=new Page<ErpCustomerCar>(1,2);
            result.setCount(carPage.getRecords().size());
            result.setData(carPage);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/removeServiceWeb")
    @ApiOperation("删除服务网络信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "webId", value = "服务网络ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<Integer> removeInsurance(Integer webId) {
        Result<Integer>  result=new Result<Integer>();
        try{

            result.setCount(1);
            result.setData(serviceWebService.deleteById(webId)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }


}

